<%@page import="com.spreedairy.portal.service.CustomFieldValueLocalServiceUtil"%>
<%@page import="com.spreedairy.portal.model.CustomFieldValue"%>
<%@page import="com.spreedairy.portal.model.CustomField"%>
<%@page import="com.liferay.portal.kernel.util.Validator"%>
<%@ page import="com.liferay.portal.kernel.util.HtmlUtil"%>

<% 
	String[] options = null; 

	if(Validator.isNotNull(defineFieldList) && defineFieldList.size() > 0) {
		for(CustomField field : defineFieldList) {
			CustomFieldValue custvalue=CustomFieldValueLocalServiceUtil.findByItemIdKeyvalue(itemId,field.getKeyValue());
			
			//Define Field add
			if(Validator.isNull(custvalue)){
		%>

<c:choose>
	<c:when test='<%= field.getKeyType().equals("text") %>'>
		<aui:input
			cssClass='<%= field.getOptional() ? "optional" : StringPool.BLANK %>'
			label="<%= HtmlUtil.escape(field.getKeyValue()) %>"
			name="<%= field.getKeyValue() %>" value="" />
	</c:when>
	<c:when test='<%= field.getKeyType().equals("textarea") %>'>
		<aui:input
			cssClass='<%= field.getOptional() ? "optional" : StringPool.BLANK %>'
			label="<%= HtmlUtil.escape(field.getKeyValue()) %>"
			name="<%= field.getKeyValue() %>" type="textarea" value=""
			wrap="soft" />
	</c:when>
	<c:when test='<%= field.getKeyType().equals("checkbox") %>'>
		<aui:input
			cssClass='<%= field.getOptional() ? "optional" : StringPool.BLANK %>'
			inlineLabel="left"
			label="<%= HtmlUtil.escape(field.getKeyValue()) %>"
			name="<%= field.getKeyValue() %>" type="checkbox" value="" />
	</c:when>
	<c:when test='<%= field.getKeyType().equals("radio") %>'>
		<aui:field-wrapper
			cssClass='<%= field.getOptional() ? "optional" : StringPool.BLANK %>'
			label="<%= HtmlUtil.escape(field.getKeyValue()) %>"
			name="<%= field.getKeyValue() %>">

			<%
						options = field.getOptionsValue().split(",");

						for (int j = 0; j < options.length; j++) {
							String optionValue = options[j];
						%>

			<aui:input inlineLabel="left"
				label="<%= HtmlUtil.escape(optionValue) %>"
				name="<%= field.getKeyValue() %>" type="radio"
				value="<%= HtmlUtil.escape(optionValue) %>" />

			<%
						}
						%>

		</aui:field-wrapper>
	</c:when>
	<c:when test='<%= field.getKeyType().equals("options") %>'>

		<%
					options = field.getOptionsValue().split(",");
					%>

		<aui:select
			cssClass='<%= field.getOptional() ? "optional" : StringPool.BLANK %>'
			label="<%= HtmlUtil.escape(field.getKeyValue()) %>"
			name="<%= field.getKeyValue() %>">

			<%
						for (int j = 0; j < options.length; j++) {
							String optionValue = options[j];
						%>

			<aui:option value="<%= HtmlUtil.escape(field.getKeyValue()) %>"><%= HtmlUtil.escape(optionValue) %></aui:option>

			<%
						}
						%>

		</aui:select>
	</c:when>
</c:choose>
<% }
	//Define Field edit
			if(Validator.isNotNull(custvalue)){%>
			
			
<c:choose>
	<c:when test='<%= field.getKeyType().equals("text") %>'>
		<aui:input
			cssClass='<%= field.getOptional() ? "optional" : StringPool.BLANK %>'
			label="<%= HtmlUtil.escape(field.getKeyValue()) %>"
			name="<%= field.getKeyValue() %>" value="<%=custvalue.getKeyValue() %>" />
	</c:when>
	<c:when test='<%= field.getKeyType().equals("textarea") %>'>
		<aui:input
			cssClass='<%= field.getOptional() ? "optional" : StringPool.BLANK %>'
			label="<%= HtmlUtil.escape(field.getKeyValue()) %>"
			name="<%= field.getKeyValue() %>" type="textarea" value="<%=custvalue.getKeyValue() %>"
			wrap="soft" />
	</c:when>
	<c:when test='<%= field.getKeyType().equals("checkbox") %>'>
		<aui:input
			cssClass='<%= field.getOptional() ? "optional" : StringPool.BLANK %>'
			inlineLabel="left"
			label="<%= HtmlUtil.escape(field.getKeyValue()) %>"
			name="<%= field.getKeyValue() %>" type="checkbox" value="<%=custvalue.getKeyValue() %>" />
	</c:when>
	<c:when test='<%= field.getKeyType().equals("radio") %>'>
		<aui:field-wrapper
			cssClass='<%= field.getOptional() ? "optional" : StringPool.BLANK %>'
			label="<%= HtmlUtil.escape(field.getKeyValue()) %>"
			name="<%= field.getKeyValue() %>">

			<%
						options = field.getOptionsValue().split(",");

						for (int j = 0; j < options.length; j++) {
							String optionValue = options[j];
						%>

			<aui:input inlineLabel="left"
				label="<%= HtmlUtil.escape(optionValue) %>"
				name="<%= field.getKeyValue() %>" type="radio"
				value="<%= HtmlUtil.escape(optionValue) %>" />

			<%
						}
						%>

		</aui:field-wrapper>
	</c:when>
	<c:when test='<%= field.getKeyType().equals("options") %>'>

		<%
					options = field.getOptionsValue().split(",");
					%>

		<aui:select
			cssClass='<%= field.getOptional() ? "optional" : StringPool.BLANK %>'
			label="<%= HtmlUtil.escape(field.getKeyValue()) %>"
			name="<%= field.getKeyValue() %>">

			<%
						for (int j = 0; j < options.length; j++) {
							String optionValue = options[j];
						%>

			<aui:option value="<%= HtmlUtil.escape(field.getKeyValue()) %>"><%= HtmlUtil.escape(optionValue) %></aui:option>

			<%
						}
						%>

		</aui:select>
	</c:when>
</c:choose>	
			
	<%		}
				
		}
	}
	else {
%>
	<p style="color:red">There are no define Fields .....</p>
<%
	}
%>